package com.p.lib.util;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;

public class GlideImageLoader {

    private Activity activity;
    private Fragment fragment;
    private Context context;
    private RequestManager manager;

    public GlideImageLoader(Activity activity) {
        this.activity = activity;
        manager = Glide.with(activity);
    }

    public GlideImageLoader(Fragment fragment) {
        this.fragment = fragment;
        manager = Glide.with(fragment);
    }

    public GlideImageLoader(Context context) {
        this.context = context;
        manager = Glide.with(context);
    }

    /**
     * 获取RequestManager对象
     * @return
     */
    public RequestManager getManager() {
        return manager;
    }

    /**
     * 加载普通图片
     * @param object
     * @param view
     */
    public void loadImage(Object object, ImageView view) {
        manager.load(object)
                .into(view);
    }

    /**
     * 加载普通图片
     * @param object
     * @param placeHolder 占位图
     * @param view
     */
    public void loadImage(Object object,int placeHolder, ImageView view) {
        manager.load(object)
                .placeholder(placeHolder)
                .into(view);
    }

    /**
     * 加载普通图片
     * @param object
     * @param error 错误图
     * @param placeHolder 占位图
     * @param view
     */
    public void loadImage(Object object, int error, int placeHolder, ImageView view) {
        manager.load(object)
                .error(error)
                .placeholder(placeHolder)
                .into(view);
    }

}